/**
 * 课件转换记录列表
 */
<template>
	<vp-main-page @refresh="loadDataList" :tableRef="tableRef">
		<template #search>
			<el-form ref="searchFormRef" :model="searchForm" @submit.prevent @keyup.enter="loadDataList" label-width="120px">
				<vp-search-row :show-more="showMore">
					<vp-search-col>
						<el-form-item prop="yswjm">
							<template #label><vp-label zh="文件名称" en="File Name"/></template>
							<el-input v-model="searchForm.yswjm" v-trim clearable></el-input>
						</el-form-item>
					</vp-search-col>
					<vp-search-col>
						<el-form-item prop="jg">
							<template #label><vp-label zh="状态" en="Status" /></template>
							<el-select v-model="searchForm.jg" clearable>
								<el-option :value="10" label="成功"></el-option>
                            	<el-option :value="20" label="失败"></el-option>
							</el-select>
						</el-form-item>
					</vp-search-col>
					<vp-search-col btn-col>
						<vp-btn-search :loading="loading" @click="loadDataList"/>
						<vp-btn-reset @click="handleSearchReset"/>
						<vp-btn-more @change="showMore = $event" />
					</vp-search-col>
				</vp-search-row>
			</el-form>
		</template>
		<template #actions>
			<el-text type="danger">Tips：删除转换记录后，课件将被重新转换！</el-text>
		</template>
		<template #table>
			<vp-vxe-table
				id="trainingCoursewareTransferRecordTable"
				ref="tableRef" 
				:data="tableData" 
				@sort-change="handleSortChange" 
				row-key="id"
				v-loading="loading"
			>	
				<vxe-column type="seq" align="center" title="#" width="50" />
				<vxe-column 
					field="yswjm" 
					title="文件名称 File Name"
					show-overflow 
					min-width="200"
				>
					<template #header><vp-label zh="文件名称" en="File Name" /></template>
				</vxe-column>
				<vxe-column 
					field="hzm" 
					title="拓展名称 Ext. Name"
					show-overflow 
					min-width="90"
				>
					<template #header><vp-label zh="拓展名称" en="Ext. Name" /></template>
				</vxe-column>
				<vxe-column 
					sortable
					field="jg" 
					title="状态 Status" 
					show-overflow
					min-width="120"
				>
					<template #header><vp-label zh="状态" en="Status" /></template>
					<template #default="{ row }">
						<el-tag type="success" v-if="row.jg === 10">成功</el-tag>
						<el-tag type="danger" v-if="row.jg === 20">失败</el-tag>
					</template>
				</vxe-column>
				<vxe-column 
					field="smyy" 
					title="消息 Message"
					show-overflow 
					min-width="120"
				>
					<template #header><vp-label zh="消息" en="Message"/></template>
				</vxe-column>
				<vxe-column 
					sortable
					field="cjsj" 
					title="转换时间 Convert Time"
					show-overflow 
					min-width="160"
				>
					<template #header><vp-label zh="转换时间" en="Convert Time"/></template>
				</vxe-column>
				<vxe-column 
					field="operation" 
					title="操作 Operation"
					fixed="right" 
					width="100"
				>
					<template #header><vp-label-operations/></template>
					<template #default="scope">
						<el-space>
							<vp-btn-del text @click="handleDelete(scope.row)"/>
						</el-space>
					</template>
				</vxe-column>
			</vp-vxe-table>
		</template>
		<template #pagination>
			<vp-pagination
				@change="loadDataList"
				:total="page.total" 
				v-model:currentPage="page.pageNum"
				v-model:pageSize="page.pageSize"
			>
			</vp-pagination>
		</template>
	</vp-main-page>
</template>
<script setup lang="ts" name="trainingCoursewareTransferRecord">
import { onMounted, reactive, ref } from 'vue'
import request from '/@/utils/request';
import { DEFAULT_PAGE } from '/@/utils/page';
import VpMessageBox from '/@/components/vp/VpMessageBox';

const searchForm = reactive({
	yswjm: "",
	jg: null,
});

const page = reactive({
	...DEFAULT_PAGE,
})

const showMore = ref(false);
const loading = ref(false);
const tableData = ref([]);

// 加载列表数据
const loadDataList = () => {
	loading.value = true;
	request.get('/training/courseware/transferRecord/list', {
		params: {
			...searchForm,
			...page,
		}
	}).then(res => {
		tableData.value = res?.data?.list || [];
		page.total = res?.data?.total || 0;
		page.pageNum = res?.data?.pageNum || 1;
	}).finally(()=>{
		loading.value = false;
	})
}

const searchFormRef = ref();
// 重置搜索条件
const handleSearchReset = ()=>{
	searchFormRef.value.resetFields();
}

// 列表字段排序
const handleSortChange = (column: any)=>{
	page.sortColumn = column.field;
	page.sortOrder = column.order;
	loadDataList()
}

onMounted(() => {
	loadDataList();
})

const tableRef = ref();

// 删除
const handleDelete = (row: any)=>{
	VpMessageBox.confirmDelete().then(()=>{
		loading.value = true;
		request.delete(`/training/courseware/transferRecord/${row.id}/${row.sjbb}`).then(res => {
			loadDataList();
		}).catch(() => {}).finally(() => {
			loading.value = false;
		})
	});
}

</script>

<style scoped lang="scss">
</style>